﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace HistogramSample
{
	public partial class Form1 : Form
	{
		public Form1()
		{
			InitializeComponent();
		}

		
		private void button2_Click(object sender, EventArgs e)
		{
			// Шаг 1: Создаём массив long[] из объекта Bitmap
			long[] data = histogramControl1.GetHistogram(new Bitmap(pictureBox1.Image));
			// Шаг 2: Выводим гистограмму
			histogramControl1.DrawHistogram(data);
		}

		private void button1_Click(object sender, EventArgs e)
		{
			try
			{
				if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
				{
					if (System.IO.File.Exists(openFileDialog1.FileName))
					{
						if (pictureBox1.Image != null)
						{
							pictureBox1.Image.Dispose();
						}
						pictureBox1.Image = Image.FromFile(openFileDialog1.FileName);
						pictureBox1.Refresh();

						Application.DoEvents();
					}
				}
			}
			catch (Exception ex)
			{
				MessageBox.Show(ex.Message);
			}
		}
	}
}
